//获取应用实例
const app = getApp();

Page({
	data: {
    isOnPhoto:false,
    isBackPhoto:false,
  },
	onLoad: function() {},

  upOnImg: function(){
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#f7982a",
      success: function (res) {
        if (!res.cancel) {
            that.chooseWxImageShop('camera',0);//手机拍照
        }
      }
    })
  },

  //选择图片
  chooseWxImageShop: function (type,status) {
    var that = this;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        console.log(res)
        if (res.tempFiles[0].size > 1048576 * 2) {
          wx.showModal({
            title: "提示",
            content: "选择的图片过大，请上传不超过2M的图片",
            showCancel: false,
            success(res) {
              if (res.confirm) {
              }
            }
          });
          return;
        }
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        if(status==0){
          that.setData({
            cardOnimg: res.tempFilePaths[0],
            isOnPhoto:true
          })
        }else{
          that.setData({
            cardBackimg: res.tempFilePaths[0],
            isBackPhoto: true
          })
        }
        
        // that.upload_file(that.data.cardOnimg, that.data.cardBackimg)
        // console.log(that.data.userimg)

      }

    })

  },


  upBackUmg:function(){
    var that = this;
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: "#f7982a",
      success: function (res) {
        if (!res.cancel) {
          if (res.tapIndex == 0) {
            that.chooseWxImageShop('album');//从相册中选择
          } else if (res.tapIndex == 1) {
            that.chooseWxImageShop('camera',1);//手机拍照
          }
        }
      }
    })
  },



  //上传实名认证
  upload_file: function (filePath1,filPath2) {
    var that = this;
    // console.log(filePath)
    wx.uploadFile({
      url: app.globalData.api + '/index.php/wap/UserAuth/add',
      filePath: filePath1,
      name: 'avatar',
      formData: {//需要的参数
        'token': app.globalData.token,
        'avatar': 'filePath',
      }, // HTTP 请求中其他额外的 form data
      header: {
        "Content-Type": "multipart/form-data"
      },
      success: function (res) {
        console.log(res)
        var data = JSON.parse(res.data);
        // // var data=res.data;
        // console.log(data);
        that.getUserMsg();
        if (data.code == 1) {
          // console.log("111111")
        }
        // wx.showToast({
        //   title: '' + res.data.msg,//提示文字
        //   duration: 2000,//显示时长
        //   mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
        //   icon: 'success', //图标，支持"success"、"loading"  
        //   success: function () { },//接口调用成功
        //   fail: function () { },  //接口调用失败的回调函数  
        //   complete: function () { } //接口调用结束的回调函数  
        // })
      },
      fail: function (res) {

      }

    })

  },

  btnsubmit:function(){
    wx.navigateBack({
      delta:1
    })
  }
});
